| Server IP : 121.121.20.254 / Your IP : 216.73.216.202 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Program Files/LibreOffice/help/en-US/text/sbasic/shared/ |
Upload File : |
<!DOCTYPE html>
<html lang="en-US" dir="ltr">
<head>
<base href="../../../../">
<noscript><meta http-equiv="refresh" content="0; URL=../../../../en-US/noscript.html"></noscript>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Round Function [VBA]</title>
<link rel="shortcut icon" href="media/navigation/favicon.ico">
<link type="text/css" href="normalize.css" rel="Stylesheet">
<link type="text/css" href="prism.css" rel="Stylesheet">
<link type="text/css" href="default.css" rel="Stylesheet">
<script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="languages.js"></script><script type="text/javascript" src="en-US/langnames.js"></script><script type="text/javascript" src="flexsearch.debug.js"></script><script type="text/javascript" src="prism.js"></script><script type="text/javascript" src="help2.js" defer></script><script type="text/javascript" src="a11y-toggle.js" defer></script><script type="text/javascript" src="paginathing.js" defer></script><script type="text/javascript" src="en-US/bookmarks.js" defer></script><script type="text/javascript" src="en-US/contents.js" defer></script><script type="text/javascript" src="help.js" defer></script><meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<header id="TopLeftHeader"><a class="symbol" href="en-US/text/shared/05/new_help.html"><div></div></a><a class="logo" href="en-US/text/shared/05/new_help.html"><p dir="auto">LibreOffice 24.2 Help</p></a><div class="dropdowns"><div class="modules">
<button type="button" data-a11y-toggle="modules-nav" id="modules" aria-haspopup="true" aria-expanded="false" aria-controls="modules-nav">Module</button><nav id="modules-nav" hidden=""></nav>
</div></div></header><aside class="leftside"><input id="accordion-1" name="accordion-menu" type="checkbox"><label for="accordion-1" dir="auto">Contents</label><div id="Contents" class="contents-treeview"></div></aside><div id="SearchFrame"><div id="Bookmarks">
<input id="search-bar" type="search" class="search" placeholder="Search in bookmarks for chosen module" dir="auto"><div class="nav-container" tabindex="0"><nav class="index" dir="auto"></nav></div>
</div></div>
<div id="DisplayArea" itemprop="softwareHelp" itemscope="true" itemtype="http://schema.org/SoftwareApplication">
<a name="Round"></a>
<a name="bm_id3150499"></a>
<meta itemprop="keywords" content="Round function (VBA)">
<h1 id="hd_id3150499" dir="auto">
<a name="Round_VBA_h1"></a>Round Function [VBA]</h1>
<p id="par_id3151384" class="paragraph" dir="auto">Rounds a numeric value to a specified number of decimal digits.</p>
<div class="embedded">
<a name="vbasupport"></a>
<div class="warning">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/warning.svg" alt="warning" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id051920171018124524" dir="auto">This constant, function or object is enabled with the statement <a target="_top" href="en-US/text/sbasic/shared/03103350.html"><span class="literal">Option VBASupport 1</span></a> placed before the executable program code in a module.</p></div>
</div>
<br>
</div>
<p id="par_id741634154499890" class="paragraph" dir="auto">This function implements the rounding rule known as "round-to-even". With this rule, whenever the difference between the number to be rounded and its nearest integer is equal to 0.5, the number is rounded to the nearest even number. See the examples <a target="_top" href="en-US/text/sbasic/shared/03170000.html#round_example">below</a> to learn more about this rule.</p>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id691634217736290" dir="auto">Be aware that VBA's <span class="literal">Round</span> function works differently than LibreOffice Calc's <span class="literal">Round</span> function. In Calc, if the difference between the number to be rounded and the nearest integer is exactly 0.5, then the number is rounded up. Hence, in Calc the number 2.5 is rounded to 3 whereas using VBA's <span class="literal">Round</span> function the value 2.5 is rounded to 2 due to the "round-to-even" rule.</p></div>
</div>
<br>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id141634153766945" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">Round(expression [,numdecimalplaces])</span>
</p>
<div class="embedded">
<a name="functvalue"></a>
<h3 id="hd_id061420171139087480" dir="auto">Return value:</h3>
</div>
<p id="par_id3150669" class="paragraph" dir="auto">Double</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id240720170117391741" class="paragraph" dir="auto"><span class="emph">expression</span>: The numeric expression to be rounded.</p>
<p id="par_id240720170117395610" class="paragraph" dir="auto"><span class="emph">numdecimalplaces</span>: Optional argument that specifies the number of decimal digits in the resulting rounded value. The default value is 0.</p>
<div class="embedded">
<a name="errorcode"></a>
<h3 id="hd_id3152869" dir="auto">Error codes:</h3>
</div>
<div class="embedded"><p class="embedded" dir="auto">5 Invalid procedure call</p></div>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Option VBASupport 1
Sub Example_Round
Dim r
r = Pi
print r ' 3,14159265358979
print Round(r, 5) ' 3,14159
r = exp(1)
print r ' 2,71828182845904
print Round(r) ' 3
End Sub
</code></pre></div>
<a name="round_example"></a>
<p id="par_id541634154843718" class="paragraph" dir="auto">The following examples illustrate the "round-to-even" rule:</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
' Rounding to the nearest integer (decimalplaces = 0)
MsgBox Round(3.5) ' 4
MsgBox Round(4.5) ' 4
MsgBox Round(5.5) ' 6
MsgBox Round(6.5) ' 6
' Rounding with 2 decimal digits (decimalplaces = 2)
MsgBox Round(1.555, 2) ' 1.56
MsgBox Round(1.565, 2) ' 1.56
MsgBox Round(1.575, 2) ' 1.58
MsgBox Round(1.585, 2) ' 1.58
</code></pre></div>
<a name="relatedtopics"></a><div class="relatedtopics">
<p class="related" itemprop="mentions" dir="auto"><a name="related"></a><span class="emph">Related Topics</span>
</p>
<div class="relatedbody" itemprop="mentions">
<p id="par_id061420170153186193" class="paragraph" dir="auto"><a target="_top" href="en-US/text/scalc/01/04060106.html#Section21">Calc ROUND function</a></p>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/shared/special_vba_func.html#VBAMath">VBA Mathematical functions</a></p></div>
</div>
</div>
</div>
<div id="DonationFrame"></div>
<footer><div id="DEBUG" class="debug">
<h3 class="bug">Help content debug info:</h3>
<p dir="auto">This page is: <a href="https://opengrok.libreoffice.org/xref/help/source/text/sbasic/shared/03170000.xhp" target="_blank">/text/sbasic/shared/03170000.xhp</a></p>
<p dir="auto">Title is: Round Function [VBA]</p>
<p id="bm_module" dir="auto"></p>
<p id="bm_system" dir="auto"></p>
<p id="bm_HID" dir="auto"></p>
</div></footer>
</body>
</html>